package com.mid;

/**
 * Created by Lxk on 2019/5/16.
 */
public class Solution151 {

    public static String reverseWords(String s) {
        String[] strs = s.split(" ");
        StringBuffer sb = new StringBuffer();
        boolean flag = false;
        for(String val : strs){
            if("".equals(val)){
                continue;
            }else{
                sb.append(reverseSingleWords(val) + " ");
            }
        }
        String str = reverseSingleWords(sb.toString().trim());
        return str;
    }

    public static String reverseSingleWords(String words){
        StringBuffer sb = new StringBuffer();
        for(int i = words.length()-1; i>=0 ;i--){
            sb.append(words.charAt(i));
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String str = "a good   example";
        System.out.println(reverseWords(str));
    }

}
